package beans;

// Generated 2 juin 2012 17:41:30 by Hibernate Tools 3.4.0.CR1

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.validation.constraints.Size;

import org.hibernate.Query;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import dao.DaoBillet;
import dao.DaoPassager;
import dao.DaoVolReel;
import dao.HibernateUtil;

/**
 * Client generated by hbm2java
 */
public class Client implements java.io.Serializable {

	private int cliNum;
	
	@Size(min=2,max=40)
	private String cliNom;
	
	@Size(min=2,max=40)
	private String cliRenom;

	@Size(min=4,max=30)
	private String cliMotPasse;

	private Date cliDateNaissance;
	private Integer cliNumRue;
	private String cliNomRue;
	private Integer cliCp;

	@NotEmpty
	private String cliVille;
	private String cliPays;
	private int cliTel;
	
	@NotEmpty
	@Email
	private String cliMail;
	private int cliNumId;
	private String cliTypeCarteCredit;
	private Integer cliNumCarteCredit;
	private Integer cliCleCarteCredit;
	private String cliDateExpCarteCredit;
	private Set<Reservation> reservations = new HashSet<Reservation>(0);
	
	private Set<VolReel> volReserve;

	public Client() {
	}

	public Client(int cliNum, String cliNom, String cliRenom,
			String cliMotPasse, Date cliDateNaissance, int cliTel,
			String cliMail, int cliNumId) {
		this.cliNum = cliNum;
		this.cliNom = cliNom;
		this.cliRenom = cliRenom;
		this.cliMotPasse = cliMotPasse;
		this.cliDateNaissance = cliDateNaissance;
		this.cliTel = cliTel;
		this.cliMail = cliMail;
		this.cliNumId = cliNumId;
	}

	public Client(int cliNum, String cliNom, String cliRenom,
			String cliMotPasse, Date cliDateNaissance, Integer cliNumRue,
			String cliNomRue, Integer cliCp, String cliVille, String cliPays,
			int cliTel, String cliMail, int cliNumId,
			String cliTypeCarteCredit, Integer cliNumCarteCredit,
			Integer cliCleCarteCredit, String cliDateExpCarteCredit,
			Set<Reservation> reservations) {
		this.cliNum = cliNum;
		this.cliNom = cliNom;
		this.cliRenom = cliRenom;
		this.cliMotPasse = cliMotPasse;
		this.cliDateNaissance = cliDateNaissance;
		this.cliNumRue = cliNumRue;
		this.cliNomRue = cliNomRue;
		this.cliCp = cliCp;
		this.cliVille = cliVille;
		this.cliPays = cliPays;
		this.cliTel = cliTel;
		this.cliMail = cliMail;
		this.cliNumId = cliNumId;
		this.cliTypeCarteCredit = cliTypeCarteCredit;
		this.cliNumCarteCredit = cliNumCarteCredit;
		this.cliCleCarteCredit = cliCleCarteCredit;
		this.cliDateExpCarteCredit = cliDateExpCarteCredit;
		this.reservations = reservations;
	}

	public int getCliNum() {
		return this.cliNum;
	}

	public void setCliNum(int cliNum) {
		this.cliNum = cliNum;
	}

	public String getCliNom() {
		return this.cliNom;
	}

	public void setCliNom(String cliNom) {
		this.cliNom = cliNom;
	}

	public String getCliRenom() {
		return this.cliRenom;
	}

	public void setCliRenom(String cliRenom) {
		this.cliRenom = cliRenom;
	}

	public String getCliMotPasse() {
		return this.cliMotPasse;
	}

	public void setCliMotPasse(String cliMotPasse) {
		this.cliMotPasse = cliMotPasse;
	}

	public Date getCliDateNaissance() {
		return this.cliDateNaissance;
	}

	public void setCliDateNaissance(Date cliDateNaissance) {
		this.cliDateNaissance = cliDateNaissance;
	}

	public Integer getCliNumRue() {
		return this.cliNumRue;
	}

	public void setCliNumRue(Integer cliNumRue) {
		this.cliNumRue = cliNumRue;
	}

	public String getCliNomRue() {
		return this.cliNomRue;
	}

	public void setCliNomRue(String cliNomRue) {
		this.cliNomRue = cliNomRue;
	}

	public Integer getCliCp() {
		return this.cliCp;
	}

	public void setCliCp(Integer cliCp) {
		this.cliCp = cliCp;
	}

	public String getCliVille() {
		return this.cliVille;
	}

	public void setCliVille(String cliVille) {
		this.cliVille = cliVille;
	}

	public String getCliPays() {
		return this.cliPays;
	}

	public void setCliPays(String cliPays) {
		this.cliPays = cliPays;
	}

	public int getCliTel() {
		return this.cliTel;
	}

	public void setCliTel(int cliTel) {
		this.cliTel = cliTel;
	}

	public String getCliMail() {
		return this.cliMail;
	}

	public void setCliMail(String cliMail) {
		this.cliMail = cliMail;
	}

	public int getCliNumId() {
		return this.cliNumId;
	}

	public void setCliNumId(int cliNumId) {
		this.cliNumId = cliNumId;
	}

	public String getCliTypeCarteCredit() {
		return this.cliTypeCarteCredit;
	}

	public void setCliTypeCarteCredit(String cliTypeCarteCredit) {
		this.cliTypeCarteCredit = cliTypeCarteCredit;
	}

	public Integer getCliNumCarteCredit() {
		return this.cliNumCarteCredit;
	}

	public void setCliNumCarteCredit(Integer cliNumCarteCredit) {
		this.cliNumCarteCredit = cliNumCarteCredit;
	}

	public Integer getCliCleCarteCredit() {
		return this.cliCleCarteCredit;
	}

	public void setCliCleCarteCredit(Integer cliCleCarteCredit) {
		this.cliCleCarteCredit = cliCleCarteCredit;
	}

	public String getCliDateExpCarteCredit() {
		return this.cliDateExpCarteCredit;
	}

	public void setCliDateExpCarteCredit(String cliDateExpCarteCredit) {
		this.cliDateExpCarteCredit = cliDateExpCarteCredit;
	}

	public Set<Reservation> getReservations() {
		return this.reservations;
	}

	public void setReservations(Set<Reservation> reservations) {
		this.reservations = reservations;
	}
	
	public ArrayList<Passager> getPassagers(){
		ArrayList<Passager> passagers = new ArrayList<Passager>();
		
		HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
		
		
		DaoPassager daoPassager = new DaoPassager();
		
		passagers = daoPassager.getPassagerFromClient(this);
		
		HibernateUtil.getSessionFactory().getCurrentSession().close();
		
		return passagers;
	}
	
	public List<VolReel> getVolReserve(){
		List<Billet> billets = new ArrayList<Billet>();
		List<VolReel> volClients = new ArrayList<VolReel>();
		DaoBillet dao = new DaoBillet();
		
		HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
		
		billets = dao.getAll();
		
		for(Billet b : billets){
			if(b.getReservation().getClient().getCliNum() == this.getCliNum()){
				volClients.add(b.getVolReel());
			}
		}
		
		
		
		HibernateUtil.getSessionFactory().getCurrentSession().close();
		
		return volClients;
	}

}
